<?php
class CampStudentModel {
	private $tableName = 'e_camp_student';
	public function getById($id) {
		$sql = "select * from $this->tableName where Id=$id limit 0,1";
		$result = mysql_query ( $sql );
		return mysql_fetch_object ( $result );
	}
	public function getMaxId() {
		$sql = "select max(Id) as maxId from $this->tableName ";
		$result = mysql_query ( $sql );
		return mysql_fetch_assoc ( $result );
	}
	//不添加Photo
	public function addInfo($info) {
		$model = new E_Camp_Student ();
		$sql = "insert into $this->tableName (";
		foreach ( $model as $key => $value ) {
			if (isset ( $info->$key )) {
				$sql .= "`" . $key . "`,";
			}
		}
		$sql = substr ( $sql, 0, - 1 );
		$sql .= ") values (";
		foreach ( $model as $key => $value ) {
			if (isset ( $info->$key )) {
				if (is_string ( $info->$key )) {
					$sql .= "'" . addslashes ( $info->$key ) . "',";
				} else {
					$sql .= "'" . $info->$key . "',";
				}
			}
		}
		$sql = substr ( $sql, 0, - 1 );
		$sql .= ");";
		echo $sql;
		mysql_query ( $sql );
		return mysql_insert_id ();
	}
	public function setInfoById($info, $id) {
		$model = new E_camp_student ();
		$sql = "update $this->tableName set ";
		foreach ( $model as $key => $value ) {
			if (isset ( $info->$key )) {
				if (is_string ( $info->$key )) {
					$sql .= "`" . $key . "`='" . addslashes ( $info->$key ) . "',";
				} else {
					$sql .= "`" . $key . "`='" . $info->$key . "',";
				}
			}
		}
		$sql = substr ( $sql, 0, - 1 );
		$sql .= " where `Id` = $id limit 1";
		return mysql_query ( $sql );
	}
	public function getByLoginInfo($studentName, $mobile) {
		$sql = "select * from $this->tableName where StudentName ='$studentName' and RegistStatus!=0 and  FirstMobile='$mobile' limit 1";
		$result = mysql_query ( $sql );
		$data = mysql_fetch_object ( $result );
		if ($data) {
			return $data;
		}
		return FALSE;
	}
	public function getList($where) {
		$sql = "select * from $this->tableName where $where order by Id asc";
		$result = mysql_query ( $sql );
		$info = array ();
		while ( $row = mysql_fetch_assoc ( $result ) ) {
			$info [] = $row;
		}
		return $info;
	}
	
	public function getCount($where) {
		$sql = "select count(*) as sum from $this->tableName where $where ";
		$result = mysql_query ( $sql );
		$row = mysql_fetch_assoc ( $result );
		return $row ['sum'];
	}
	public function delByStudentId($studentId) {
		$sql = "delete from $this->tableName where Id=$studentId limit 1";
		return mysql_query ( $sql );
	}
}